﻿package string;

public class 两个字符串是否互为变形词 {
	public static boolean isDeformation(String str1, String str2){

		if(str1 == null||str2==null||str1.length()!=str2.length())
			return false;		
		char[] chr1 = str1.toCharArray();
		char[] chr2 = str2.toCharArray();
		int[] help = new int[256];
		for(int i=0; i< chr1.length; i++){
			help[chr1[i]]++;
		}
		
		for(int i=0;i<chr2.length ;i++){
			if(help[chr2[i]]-- ==0)//先减去1，再作比较
				return false;
		}
		return true;

	}
	public static void main(String[] args){
		System.out.println(isDeformation("cba","abc"));
	}
}
